<script setup lang="ts">
import { useDraggable } from '@vueuse/core'
// ------------------use------------------
// #region
withDefaults(
  defineProps<{
    title?: string
  }>(),
  {
    title: '标题',
  },
)
const targetRef = ref<HTMLElement | null>(null)
const handleRef = ref<HTMLElement | null>(null)
const { style } = useDraggable(() => toValue(targetRef), {
  handle: handleRef,
  initialValue: () => {
    const winWidth = window.innerWidth
    const winHeight = window.innerHeight
    return {
      x: winWidth - 260,
      y: winHeight - 460,
    }
  },
})
// #endregion
// ------------------静态变量------------------
// #region

// #endregion
// ------------------动态变量------------------
// #region

// #endregion
// ------------------ref-----------
// #region

// #endregion
// ------------------reactive------
// #region

// #endregion
// ------------------computed------
// #region

// #endregion
// ------------------生命周期------------------
// #region

// #endregion
// ------------------内置方法---------------------
// #region

// #endregion
// ------------------方法---------------------
// #region

// #endregion
</script>

<template>
  <div ref="targetRef" :style="style" class="drag-modal">
    <div ref="handleRef" class="drag-modal-head">
      {{ title }}
    </div>
    <div class="padding-sm">
      <slot />
    </div>
  </div>
</template>

<style lang="scss">
//------------------组件样式------------------
.drag-modal {
  position: fixed;
  width: 200px;
  border-radius: 4px;
  overflow: hidden;
  background: #ffffff;
  z-index: 3000;
  box-shadow: 0 0 10px rgba(0, 0, 0, 0.2);
  &-head {
    padding: 10px 16px;
    background: #eeeeee;
    text-align: center;
    cursor: move;
  }
  .el-form {
    .el-form-item {
      margin-bottom: 8px;
    }
    .el-form-item:last-of-type {
      margin-bottom: 0px;
    }
  }
}
//-------------样式穿透-------------
</style>
